package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/system/test")
@Api(tags = "消息队列")
public class MessageController  extends BaseController {

    private final AmqpTemplate amqpTemplate;

    public MessageController(AmqpTemplate amqpTemplate) {
        this.amqpTemplate = amqpTemplate;
    }
    @PreAuthorize("@ss.hasPermi('system:dept:list')")
    @GetMapping("/list")
    public AjaxResult list()
    {

        String message="";
        String routingKey="";
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setDeliveryMode(MessageDeliveryMode.PERSISTENT);  // 设置消息持久化
        Message amqpMessage = new Message(message.getBytes(), messageProperties);

        // 发送消息到指定交换机，并通过路由键进行路由
        amqpTemplate.send("topicExchange", routingKey, amqpMessage);
        return success();
    }

    // 发送消息到主题交换机
    public void sendMessage(String message, String routingKey) {


    }
}
